package com.cheetah.start.module.system.controller;

import com.cheetah.start.common.base.result.Result;
import com.cheetah.start.common.base.result.ResultController;
import com.cheetah.start.common.base.result.ResultTree;
import com.cheetah.start.module.system.domain.SysMenu;
import com.cheetah.start.module.system.service.SysRoleMenuService;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Valid;

import java.util.List;

/**
 * 角色权限控制器
 *
 * @author Feel
 * @date 2021/10/15
 */
@Slf4j
@Valid
@Controller
@Mapping("/roleMenu")
public class SysRoleMenuController extends ResultController {

    @Inject
    SysRoleMenuService sysRoleMenuService;


    /**
     * 获取角色权限
     *
     * @param roleId 角色id
     * @return {@link Result}
     */
    @Get
    @Mapping("/get")
    public ResultTree get(Integer roleId) {
        List<SysMenu> menuByRoleId = sysRoleMenuService.getMenuByRoleId(roleId);
        return dataTree(menuByRoleId);
    }

    /**
     * 添加
     *
     * @param roleId  角色id
     * @param menuIds 菜单id
     * @return {@link Result}
     */
    @Post
    @Mapping("/add")
    public Result add(Integer roleId, String[] menuIds) {
        boolean res = sysRoleMenuService.add(roleId, menuIds);
        return decide(res);
    }
}
